package com.pai4j.netty.gateway.handler;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;


public class NettyGatewayChannelInitializer extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {

        ChannelPipeline pipeline = socketChannel.pipeline();

        // 设置http请求编解码处理器，使用默认的
        pipeline.addLast(new HttpServerCodec());

        // 合并http请求，设置允许请求数据大小，默认64kb
        pipeline.addLast(new HttpObjectAggregator(65536 * 5));

        // 自定义网关路由handler
        pipeline.addLast(new NettyGatewayRouterHandler());
    }
}
